// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);//vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state:{//存放状态
		"username":"foo",
		"age":18,
		count: 1,
		messages:[],
		random:0   // 监听直播间成员进出
	},
	
	mutations: {
			add(state,n=2) {
				// 变更状态
				state.count += n
			},
			addmessage(state,info){
				let arr = JSON.parse(JSON.stringify(state.messages))
				// state.messages = []
				state.messages.push(info)
				// arr.push(info)
				// state.messages = arr
				console.log(state.messages)
			},
			clear(state,group_id){
				let messages = state.messages
				messages = messages.filter(item=>item.group_id!=group_id)
				state.messages = messages
			},
			changerandom(state){
				state.random = Math.random() + Date.now()
			}
		}
})
export default store
